using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class FacilityMap : EntityTypeConfiguration<Facility>
    {
        public FacilityMap()
        {
            // Primary Key
            this.HasKey(t => t.FacilityID);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.FAC_Phone)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Facility");
            this.Property(t => t.FacilityID).HasColumnName("FacilityID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Floor).HasColumnName("Floor");
            this.Property(t => t.room).HasColumnName("room");
            this.Property(t => t.WardID).HasColumnName("WardID");
            this.Property(t => t.GenderID).HasColumnName("GenderID");
            this.Property(t => t.TypeID).HasColumnName("TypeID");
            this.Property(t => t.UsageType).HasColumnName("UsageType");
            this.Property(t => t.MinUsage).HasColumnName("MinUsage");
            this.Property(t => t.Active).HasColumnName("Active");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.FAC_ID).HasColumnName("FAC_ID");
            this.Property(t => t.FAC_Phone).HasColumnName("FAC_Phone");

            // Relationships
            this.HasRequired(t => t.FacilityType)
                .WithMany(t => t.Facilities)
                .HasForeignKey(d => d.TypeID);
            this.HasRequired(t => t.Ward)
                .WithMany(t => t.Facilities)
                .HasForeignKey(d => d.WardID);

        }
    }
}
